 import {
     COURT_DATE_GET_REQUEST,
     COURT_DATE_GET_SUCCESS,
     COURT_DATE_GET_FAILURE,

     COURT_FIELD_GET_REQUEST,
     COURT_FIELD_GET_SUCCESS,
     COURT_FIELD_GET_FAILURE,

     COURT_FIELD_SELECTED,
     COURT_FIELD_UNSELECTED,
     COURT_FIELD_CLEAR,
     SET_LIST_LOADING_STATUS
 } from '../mutation-types';

 import Vue from 'vue';

 const state = {
     courtDate: {},
     courtField: {},
     courtFieldSelected: []
 }
 const mutations = {
     /*===============courtDate mutation start====================*/

     [COURT_DATE_GET_SUCCESS](state, courtDate, court) {
         console.log("COURT_DATE_GET_SUCCESS");
         const _courtDate = "court_" + court + "_date_";
         if (!state.courtDate[_courtDate]) {
             Vue.set(state.courtDate, _courtDate, []);
         }
         state.courtDate[_courtDate] = courtDate;
     },
     [COURT_DATE_GET_REQUEST](state) {
         console.log("COURT_DATE_GET_REQUEST");
     },
     [COURT_DATE_GET_FAILURE](state) {
         console.log("COURT_DATE_GET_FAILURE");
     },
     /*===============courtDate mutation end====================*/



     /*===============courtField mutation start================*/
     [COURT_FIELD_GET_SUCCESS](state, courtField, court, date) {
         console.log("COURT_FIELD_GET_SUCCESS");
         const _courtField = "court_" + court + "_date_" + date + "_field_";
         if (!state.courtField[_courtField]) {
             Vue.set(state.courtField, _courtField, []);
         }
         state.courtField[_courtField] = courtField;
     },
     [COURT_FIELD_GET_REQUEST](state) {
         console.log("COURT_FIELD_GET_REQUEST");
     },
     [COURT_FIELD_GET_FAILURE](state) {
         console.log("COURT_FIELD_GET_FAILURE");
     },
     /*===============courtField mutation end==================*/


     /*===========courtFieldSelecte mutation start============*/
     [COURT_FIELD_SELECTED](state, fieldItem) {
         console.log("COURT_FIELD_SELECTED");

         const isf = state.courtFieldSelected.find(f => f && f.id === fieldItem.id);

         if (!isf) {
             state.courtFieldSelected.push(fieldItem);
         } else {
             console.log("Already Selected fieldId" + fieldItem.id)
         }
     },

     [COURT_FIELD_UNSELECTED](state, fieldItem) {
         console.log("COURT_FIELD_UNSELECTED");
         var curSelected = state.courtFieldSelected;
         curSelected.some((f, i) => {
             var iss = f.id === fieldItem.id;
             if (iss) {
                 console.log("COURT_FIELD_UNSELECTED" + fieldItem.id);
                 state.courtFieldSelected.splice(i, 1);
             }
             return iss;
         });
     },
     /*===========courtFieldSelected mutation end==============*/



     //COURT_FIELD_CLEAR,




 }
 export default {
     state,
     mutations
 }
